package gui;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

/*
 * Returns a JPanel with an Image inside of it.
 * Useful for easy load of pretty images from file.
 * Usage: Pass in the desired file name to the constructor
 * File must be located inside images folder!
 * 
 * Author: rjdunlap
 */
class ImagePanel extends JPanel
{

	private static final long serialVersionUID = -6009416159129827447L;
	private BufferedImage image;
	
	//Contructor - Pass in filename that is inside images folder
	public ImagePanel(String imageName) {
       try {                
          image = ImageIO.read(new File("./images/"+ imageName));
       } catch (IOException ex) {
            //File does not exist or error
    	    //Simply ignore.
       }
    }

	//Draw
    @Override
    public void paintComponent(Graphics g) {
        g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters

    }
	
}